home *** CD-ROM | disk | FTP | other *** search
/ Aminet 7 / Aminet 7 - August 1995.iso / Aminet / dev / gui / textfield.lha / Textfield / TestClass / TestClass.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-15  |  17.9 KB  |  641 lines

  1. /*
  2.  * TestClass.c
  3.  *
  4.  * This is a sample program that uses the TextField BOOPSI class.
  5.  * It is modeled after an example in the RKRM Libraries book on
  6.  * the RKMButClass.  It is provided to show how to use a TextField.gadget
  7.  * BOOPSI object and shows general techniques and functionality.
  8.  *
  9.  * Opening the textfield.gadget library is done by TextFieldAuto.c.
  10.  * The variable TextFieldBase has the library base, and the variable
  11.  * TextFieldClass has the class pointer.
  12.  *
  13.  * See the autodoc if you do not use the SAS/C auto-open feature or
  14.  * if you have another compiler.
  15.  *
  16.  * This code compiles with SAS/C 6.50+.
  17.  */
  18.  
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21. #include <string.h>
  22.  
  23. #include <exec/types.h>
  24. #include <intuition/intuition.h>
  25. #include <intuition/classes.h>
  26. #include <intuition/classusr.h>
  27. #include <intuition/imageclass.h>
  28. #include <intuition/gadgetclass.h>
  29. #include <intuition/cghooks.h>
  30. #include <intuition/icclass.h>
  31. #include <graphics/gfxmacros.h>
  32. #include <graphics/text.h>
  33. #include <utility/tagitem.h>
  34. #include <gadgets/textfield.h>
  35. #include <libraries/gadtools.h>
  36.  
  37. #include <clib/alib_protos.h>
  38.  
  39. #include <proto/exec.h>
  40. #include <proto/iffparse.h>
  41. #include <proto/intuition.h>
  42. #include <proto/graphics.h>
  43. #include <proto/utility.h>
  44. #include <proto/textfield.h>
  45. #include <proto/gadtools.h>
  46.  
  47. /*
  48.  * External prototypes
  49.  */
  50.  
  51. extern int SetupScreen( void );
  52. extern void CloseDownScreen( void );
  53. extern int HandleTextFieldPrefsIDCMP( void );
  54. extern int OpenTextFieldPrefsWindow( void );
  55. extern void CloseTextFieldPrefsWindow( void );
  56. extern struct Window *TextFieldPrefsWnd;
  57.  
  58. /*
  59.  * Local prototypes
  60.  */
  61.  
  62. static void MainLoop(struct Menu *menu_strip);
  63. static BOOL SetupPrefsWindow(void);
  64. static void ShutdownPrefsWindow(void);
  65. static void GetGadgetRect(struct Window *window, struct Gadget *gadget, struct Rectangle *rect);
  66. static void ActivateTabGadget(struct Window *window);
  67. static BOOL DoMenu(UWORD menu, UWORD item);
  68.  
  69. /*
  70.  * Local variables
  71.  */
  72.  
  73. static const char vers[] = "\0$VER: TestTextfield 3.1 " __AMIGADATE__;
  74.  
  75. static char initial_text[] = "Sample text placed immediately into the gadget.\nType into the object.\nOr try AMIGA-[, AMIGA-=, AMIGA-], or AMIGA-\\.\n",
  76.             more_text[] = "I think the gadget looks best with the double-bevel border and a medium cursor speed.";
  77.  
  78. static struct TagItem prop2text[] = {
  79.     { PGA_Top, TEXTFIELD_Top },
  80.     { TAG_DONE }
  81. };
  82. static struct TagItem text2prop[] = {
  83.     { TEXTFIELD_Top, PGA_Top },
  84.     { TEXTFIELD_Visible, PGA_Visible },
  85.     { TEXTFIELD_Lines, PGA_Total },
  86.     { TAG_DONE }
  87. };
  88. static struct TagItem up2text[] = {
  89.     { GA_ID, TEXTFIELD_Up },
  90.     { TAG_DONE }
  91. };
  92. static struct TagItem down2text[] = {
  93.     { GA_ID, TEXTFIELD_Down },
  94.     { TAG_DONE }
  95. };
  96.  
  97. enum {
  98.     PROJECT_MENU,
  99.     EDIT_MENU,
  100. };
  101.  
  102. enum {
  103.     ABOUT_ITEM,
  104.     QUIT_ITEM = 2
  105. };
  106.  
  107. enum {
  108.     CUT_ITEM,
  109.     COPY_ITEM,
  110.     COPYALL_ITEM,
  111.     PASTE_ITEM,
  112.     UNDO_ITEM = 5,
  113.     ERASE_ITEM = 7
  114. };
  115.  
  116. static struct NewMenu menus[] = {
  117.     { NM_TITLE, "Project",          0, 0, 0, 0 },
  118.     {  NM_ITEM, "About",        "?", 0, 0, 0 },
  119.     {  NM_ITEM, NM_BARLABEL,      0, 0, 0, 0 },
  120.     {  NM_ITEM, "Quit",            "Q", 0, 0, 0 },
  121.     { NM_TITLE, "Edit",              0, 0, 0, 0 },
  122.     {  NM_ITEM, "Cut",            "X", 0, 0, 0 },
  123.     {  NM_ITEM, "Copy",            "C", 0, 0, 0 },
  124.     {  NM_ITEM, "Copy All",        "K", 0, 0, 0 },
  125.     {  NM_ITEM, "Paste",        "V", 0, 0, 0 },
  126.     {  NM_ITEM, NM_BARLABEL,      0, 0, 0, 0 },
  127.     {  NM_ITEM, "Undo",            "U", 0, 0, 0 },
  128.     {  NM_ITEM, NM_BARLABEL,      0, 0, 0, 0 },
  129.     {  NM_ITEM, "Erase",        "E", 0, 0, 0 },
  130.     {   NM_END, NULL,              0, 0, 0, 0 }
  131. };
  132.  
  133. static struct EasyStruct about_req = {
  134.     sizeof(struct EasyStruct),
  135.     0,
  136.     "About TestTextField",
  137.     "TestTextField shows how to\nuse the textfield gadget.\n\n%s",
  138.     "Okay"
  139. };
  140.  
  141. /*
  142.  * Global variables
  143.  */
  144.  
  145. struct Window *window;
  146. struct Gadget *text1_object, *prop_object, *up_object, *down_object;
  147. ULONG length, window_sig, prefs_sig, sigs, style;
  148. UWORD *pens;
  149.  
  150. /*
  151.  * Functions
  152.  */
  153.  
  154. void main(void)
  155. {
  156.     struct IntuiText text1_title;
  157.     struct DrawInfo *draw_info;
  158.     struct ClipboardHandle *clip_handle, *undo_handle;
  159.     struct Image *up_image, *down_image;
  160.     APTR *visual_info;
  161.     UWORD gap_w, gap_h;
  162.     struct Menu *menu_strip;
  163.  
  164.     if (!SetupPrefsWindow()) {
  165.         printf("Cannot setup prefs window.\n");
  166.         return;
  167.     }
  168.     prefs_sig = 1L << TextFieldPrefsWnd->UserPort->mp_SigBit;
  169.  
  170.     /* Open the window */
  171.     window = OpenWindowTags(NULL,    WA_Flags,            WFLG_DEPTHGADGET|WFLG_DRAGBAR|WFLG_CLOSEGADGET|WFLG_SIZEGADGET
  172.                                                         |WFLG_SIZEBBOTTOM|WFLG_SIZEBRIGHT,
  173.                                     WA_Activate,        TRUE,
  174.                                     WA_IDCMP,            IDCMP_CLOSEWINDOW|IDCMP_VANILLAKEY|IDCMP_RAWKEY|IDCMP_MENUPICK,
  175.                                     WA_Width,            320,
  176.                                     WA_Height,            200,
  177.                                     WA_NoCareRefresh,    TRUE,
  178.                                     WA_NewLookMenus,    TRUE,
  179.                                     WA_ScreenTitle,        "Testing textfield.gadget",
  180.                                     TAG_END);
  181.  
  182.     if (window) {
  183.         window_sig = 1L << window->UserPort->mp_SigBit;
  184.         sigs = prefs_sig | window_sig;
  185.         /* Get the DrawInfo since sysiclass needs it */
  186.         draw_info = GetScreenDrawInfo(window->WScreen);
  187.  
  188.         if (draw_info) {
  189.             pens = draw_info->dri_Pens;
  190.  
  191.             /* Make a title for the gadget */
  192.             text1_title.FrontPen = pens[TEXTPEN];
  193.             text1_title.BackPen = pens[BACKGROUNDPEN];  /* don't really need to set for JAM1 */
  194.             text1_title.DrawMode = JAM1;
  195.             text1_title.LeftEdge = 0;
  196.             text1_title.TopEdge = -(window->WScreen->RastPort.TxHeight + 1);
  197.             text1_title.ITextFont = NULL;
  198.             text1_title.IText = "Gadget label:";
  199.             text1_title.NextText = NULL;
  200.  
  201.             /* Setup the gaps */
  202.             gap_w = 20;
  203.             gap_h = window->RPort->TxHeight;
  204.  
  205.             /* Make some changes in the window limits */
  206.             WindowLimits(window, 160, window->BorderTop + window->BorderBottom + window->WScreen->RastPort.TxHeight + 46, -1, -1);
  207.  
  208.             /* Create the gadgets/images with interconnection */
  209.             prop_object = NewObject(NULL, "propgclass",
  210.                                     GA_ID,            2,
  211.                                     GA_Top,            window->BorderTop,
  212.                                     GA_RelRight,    -(window->BorderRight - 5),
  213.                                     GA_Width,        window->BorderRight - 8,
  214.                                     GA_RelHeight,    -(window->BorderTop + (3 * window->BorderBottom)) - 2,
  215.                                     GA_RightBorder,    TRUE,
  216.                                     ICA_MAP,        prop2text,
  217.                                     PGA_NewLook,    TRUE,
  218.                                     PGA_Borderless,    TRUE,
  219.                                     PGA_Visible,    50,        /* will get set later */
  220.                                     PGA_Total,        50,        /* will get set later */
  221.                                     TAG_END);
  222.  
  223.             up_image = NewObject(NULL, "sysiclass",
  224.                                     SYSIA_DrawInfo,    draw_info,
  225.                                     SYSIA_Which,    UPIMAGE,
  226.                                     IA_Width,        window->BorderRight,
  227.                                     IA_Height,        window->BorderBottom,
  228.                                     TAG_END);
  229.  
  230.             down_image = NewObject(NULL, "sysiclass",
  231.                                     SYSIA_DrawInfo,    draw_info,
  232.                                     SYSIA_Which,    DOWNIMAGE,
  233.                                     IA_Width,        window->BorderRight,
  234.                                     IA_Height,        window->BorderBottom,
  235.                                     TAG_END);
  236.  
  237.             up_object = NewObject(NULL, "buttongclass",
  238.                                     GA_RelBottom,    -(3 * window->BorderBottom) - 1,
  239.                                     GA_RelRight,    -(window->BorderRight - 1),
  240.                                     GA_Height,        window->BorderBottom,
  241.                                     GA_Width,        window->BorderRight,
  242.                                     GA_Image,        up_image,
  243.                                     GA_RightBorder,    TRUE,
  244.                                     //GA_RelVerify,    TRUE,
  245.                                     GA_Previous,    prop_object,
  246.                                     ICA_MAP,        up2text,
  247.                                     TAG_END);
  248.  
  249.             down_object = NewObject(NULL, "buttongclass",
  250.                                     GA_RelBottom,    -(2 * window->BorderBottom),
  251.                                     GA_RelRight,    -(window->BorderRight - 1),
  252.                                     GA_Height,        window->BorderBottom,
  253.                                     GA_Width,        window->BorderRight,
  254.                                     GA_Image,        down_image,
  255.                                     GA_RightBorder,    TRUE,
  256.                                     //GA_RelVerify,    TRUE,
  257.                                     GA_Previous,    up_object,
  258.                                     ICA_MAP,        down2text,
  259.                                     TAG_END);
  260.  
  261.             /* Open the clipboard; no need to verify */
  262.             clip_handle = OpenClipboard(0);
  263.             undo_handle = OpenClipboard(42);
  264.  
  265.             text1_object = NewObject(TextFieldClass, NULL,
  266.                                     GA_ID,                    1,
  267.                                     GA_Top,                    window->BorderTop + gap_h,
  268.                                     GA_Left,                window->BorderLeft + gap_w,
  269.                                     GA_RelWidth,            -(window->BorderLeft + window->BorderRight + 2 * gap_w),
  270.                                     GA_RelHeight,            -(window->BorderTop + window->BorderBottom + 2 * gap_h),
  271.                                     GA_Previous,            down_object,
  272.                                     //GA_TabCycle,            TRUE,
  273.                                     GA_IntuiText,            &text1_title,
  274.  
  275.                                     ICA_MAP,                text2prop,
  276.                                     ICA_TARGET,                prop_object,
  277.  
  278.                                     TEXTFIELD_Text,            (ULONG)initial_text,
  279.                                     TEXTFIELD_UserAlign,    TRUE,
  280.                                     TEXTFIELD_ClipStream,    clip_handle,
  281.                                     TEXTFIELD_UndoStream,    undo_handle,
  282.                                     TEXTFIELD_Border,        TEXTFIELD_BORDER_DOUBLEBEVEL,
  283.                                     TEXTFIELD_BlinkRate,    500000,
  284.                                     TEXTFIELD_TabSpaces,    4,
  285.                                     TEXTFIELD_NonPrintChars,    TRUE,
  286.  
  287.                                     /*TEXTFIELD_VCenter,        TRUE,
  288.                                     TEXTFIELD_CursorPos,    10,
  289.                                     TEXTFIELD_Partial,        TRUE,
  290.                                     TEXTFIELD_MaxSize,        1000,
  291.                                     TEXTFIELD_AcceptChars,    "+-1234567890\n",
  292.                                     TEXTFIELD_Alignment,    TEXTFIELD_ALIGN_CENTER,
  293.                                     TEXTFIELD_TextAttr,        (ULONG)&font,
  294.                                     TEXTFIELD_Spacing,        10,
  295.                                     TEXTFIELD_FontStyle,    style,*/
  296.                                     TAG_END);
  297.  
  298.             /* Check if they were all created okay */
  299.             if (text1_object && prop_object && up_image && down_image && up_object && down_object) {
  300.                 ULONG cur;
  301.  
  302.                 /* Do menu stuff */
  303.                 visual_info = GetVisualInfo(window->WScreen, TAG_END);
  304.                 if (visual_info) {
  305.                     menu_strip = CreateMenus(menus, TAG_END);
  306.                     if (menu_strip) {
  307.                         if (LayoutMenus(menu_strip, visual_info, GTMN_NewLookMenus, TRUE, TAG_END)) {
  308.                             if (!SetMenuStrip(window, menu_strip)) {
  309.                                 printf("Can't set menu strip; no menus.\n");
  310.                             }
  311.                         } else {
  312.                             printf("Can't layout menus; no menus.\n");
  313.                         }
  314.                     } else {
  315.                         printf("Can't create menus; no menus.\n");
  316.                     }
  317.                 } else {
  318.                     printf("Can't get visual info; no menus.\n");
  319.                 }
  320.  
  321.                 /* Adjust some of the interconnections */
  322.                 SetGadgetAttrs(prop_object, window, NULL, ICA_TARGET, text1_object, TAG_END);
  323.                 SetGadgetAttrs(up_object, window, NULL, ICA_TARGET, text1_object, TAG_END);
  324.                 SetGadgetAttrs(down_object, window, NULL, ICA_TARGET, text1_object, TAG_END);
  325.  
  326.                 AddGList(window, prop_object, -1, -1, NULL);
  327.                 RefreshGList(prop_object, window, NULL, -1);
  328.  
  329.                 ActivateGadget(text1_object, window, NULL);
  330.                 SetWindowTitles(window, "<-- Scroll to bottom; click to go to top", (UBYTE *)-1);
  331.                 MainLoop(menu_strip);
  332.                 SetGadgetAttrs(text1_object, window, NULL, TEXTFIELD_CursorPos, 0, TAG_DONE);
  333.  
  334.                 ActivateGadget(text1_object, window, NULL);
  335.                 SetWindowTitles(window, "<-- Move cursor; click to remember", (UBYTE *)-1);
  336.                 MainLoop(menu_strip);
  337.                 GetAttr(TEXTFIELD_CursorPos, text1_object, &cur);
  338.  
  339.                 SetWindowTitles(window, "<-- Click to reset cursor", (UBYTE *)-1);
  340.                 MainLoop(menu_strip);
  341.                 SetGadgetAttrs(text1_object, window, NULL, TEXTFIELD_CursorPos, cur, TAG_DONE);
  342.                 ActivateGadget(text1_object, window, NULL);
  343.  
  344.                 SetWindowTitles(window, "<-- Click to move gadget position", (UBYTE *)-1);
  345.                 MainLoop(menu_strip);
  346.                 { // Shows how to change the size on the fly
  347.                   // Also shows the special case of handling size change with GA_Rel#?
  348.                     struct Rectangle rect;
  349.  
  350.                     GetGadgetRect(window, text1_object, &rect);
  351.                     SetAPen(window->RPort, pens[BACKGROUNDPEN]);
  352.                     RectFill(window->RPort, rect.MinX, rect.MinY, rect.MaxX, rect.MaxY);
  353.                     SetGadgetAttrs(text1_object, window, NULL,
  354.                                     GA_Left,        window->BorderLeft,
  355.                                     GA_Top,            window->BorderTop,
  356.                                     GA_RelWidth,    -(window->BorderLeft + window->BorderRight),
  357.                                     GA_RelHeight,    -(window->BorderTop + window->BorderBottom),
  358.                                     GA_IntuiText,    NULL,
  359.                                     TAG_DONE);
  360.                     RefreshGList(text1_object, window, NULL, 1);
  361.                 }
  362.                 //ActivateGadget(text1_object, window, NULL);
  363.  
  364.                 SetWindowTitles(window, "<-- Click to replace text", (UBYTE *)-1);
  365.                 MainLoop(menu_strip);
  366.                 SetGadgetAttrs(text1_object, window, NULL, TEXTFIELD_Text, more_text, TAG_DONE);
  367.                 //ActivateGadget(text1_object, window, NULL);
  368.  
  369.                 SetWindowTitles(window, "<-- Click to select 10 chars", (UBYTE *)-1);
  370.                 MainLoop(menu_strip);
  371.                 SetGadgetAttrs(text1_object, window, NULL, TEXTFIELD_SelectSize, 10, TAG_DONE);
  372.                 ActivateGadget(text1_object, window, NULL);
  373.  
  374.                 SetWindowTitles(window, "<-- Click to print text and info", (UBYTE *)-1);
  375.                 MainLoop(menu_strip);
  376.                 SetGadgetAttrs(text1_object, window, NULL, TEXTFIELD_ReadOnly, TRUE, TAG_DONE);
  377.                 if (GetAttr(TEXTFIELD_Size, text1_object, &length)) {
  378.                     unsigned char *my_buffer = malloc(length + 1);
  379.                     if (my_buffer) {
  380.                         unsigned char *text_buffer;
  381.                         my_buffer[length] = 0;
  382.                         if (GetAttr(TEXTFIELD_Text, text1_object, (ULONG *)&text_buffer)) {
  383.                             if (text_buffer) {
  384.                                 memcpy(my_buffer, text_buffer, length);
  385.                                 printf("%s", my_buffer);
  386.                                 printf("\n");
  387.                             }
  388.                         }
  389.                         free(my_buffer);
  390.                     }
  391.                 }
  392.                 SetGadgetAttrs(text1_object, window, NULL, TEXTFIELD_ReadOnly, FALSE, TAG_DONE);
  393.                 if (GetAttr(TEXTFIELD_Visible, text1_object, &length)) {
  394.                     printf("Visible lines: %d\n", length);
  395.                 }
  396.                 if (GetAttr(TEXTFIELD_Lines, text1_object, &length)) {
  397.                     printf("  Total lines: %d\n", length);
  398.                 }
  399.                 if (GetAttr(TEXTFIELD_Size, text1_object, &length)) {
  400.                     printf("         Size: %d\n", length);
  401.                 }
  402.                 if (GetAttr(TEXTFIELD_Top, text1_object, &length)) {
  403.                     printf("     Top line: %d\n", length);
  404.                 }
  405.                 if (GetAttr(TEXTFIELD_CursorPos, text1_object, &length)) {
  406.                     printf("       Cursor: %d\n", length);
  407.                 }
  408.                 if (GetAttr(TEXTFIELD_Modified, text1_object, &length)) {
  409.                     printf("     Modified: %s\n", (length ? "TRUE" : "FALSE"));
  410.                 }
  411.  
  412.                 SetWindowTitles(window, "<-- Click to quit", (UBYTE *)-1);
  413.                 MainLoop(menu_strip);
  414.  
  415.                 RemoveGList(window, prop_object, -1);
  416.  
  417.                 /* Clean menu stuff */
  418.                 if (window->MenuStrip) {
  419.                     ClearMenuStrip(window);
  420.                 }
  421.                 if (menu_strip) {
  422.                     FreeMenus(menu_strip);
  423.                 }
  424.                 if (visual_info) {
  425.                     FreeVisualInfo(visual_info);
  426.                 }
  427.             } else {
  428.                 printf("Couldn't get objects.\n");
  429.             }
  430.  
  431.             /* Clean up any objects */
  432.             DisposeObject(text1_object);
  433.             DisposeObject(down_object);
  434.             DisposeObject(up_object);
  435.             DisposeObject(down_image);
  436.             DisposeObject(up_image);
  437.             DisposeObject(prop_object);
  438.  
  439.             /* Close the clipboard */
  440.             if (undo_handle) {
  441.                 CloseClipboard(undo_handle);
  442.             }
  443.             if (clip_handle) {
  444.                 CloseClipboard(clip_handle);
  445.             }
  446.  
  447.             FreeScreenDrawInfo(window->WScreen, draw_info);
  448.         } else {
  449.             printf("Couldn't get draw info.\n");
  450.         }
  451.         CloseWindow(window);
  452.     } else {
  453.         printf("Couldn't open window.\n");
  454.     }
  455.  
  456.     ShutdownPrefsWindow();
  457. }
  458.  
  459. /*
  460.  * GetGadgetRect()
  461.  *
  462.  * This function gets the actual Rectangle where a gadget exists
  463.  * in a window.  The special cases it handles are all the REL#?
  464.  * (relative positioning flags).
  465.  *
  466.  * You need the actual position if you want to RectFill() to clear
  467.  * the space a gadget covers or something like that.
  468.  *
  469.  * The function takes a struct Window pointer, a struct Gadget
  470.  * pointer, and a struct Rectangle pointer.  It uses the window and
  471.  * gadget to fill in the rectangle.
  472.  */
  473.  
  474. static void GetGadgetRect(struct Window *window, struct Gadget *gadget, struct Rectangle *rect)
  475. {
  476.     rect->MinX = rect->MaxX = gadget->LeftEdge;
  477.     if (gadget->Flags & GFLG_RELRIGHT) rect->MinX += window->Width - 1;
  478.     rect->MinY = rect->MaxY = gadget->TopEdge;
  479.     if (gadget->Flags & GFLG_RELBOTTOM) rect->MinY += window->Height - 1;
  480.     rect->MaxX += gadget->Width;
  481.     if (gadget->Flags & GFLG_RELWIDTH) rect->MaxX += window->Width - 1;
  482.     rect->MaxY += gadget->Height;
  483.     if (gadget->Flags & GFLG_RELHEIGHT) rect->MaxY += window->Height - 1;
  484. }
  485.  
  486. /*
  487.  * MainLoop()
  488.  *
  489.  * Handles all window IDCMP messages
  490.  */
  491.  
  492. static void MainLoop(struct Menu *menu_strip)
  493. {
  494.     struct IntuiMessage *msg;
  495.     ULONG done = FALSE;
  496.     UWORD menu_num;
  497.  
  498.     while (!done) {
  499.         HandleTextFieldPrefsIDCMP();
  500.         while (msg = (struct IntuiMessage *)GetMsg((struct MsgPort *)window->UserPort)) {
  501.             if (msg->Class == IDCMP_CLOSEWINDOW) {
  502.                 done = TRUE;
  503.             } else if (msg->Class == IDCMP_VANILLAKEY) {
  504.                 if (msg->Code == 0x09) {
  505.                     // Activate first gadget that supports tab cycling if TAB is pressed
  506.                     ActivateTabGadget(window);
  507.                 } else {
  508.                     DisplayBeep(NULL);
  509.                 }
  510.             } else if (msg->Class == IDCMP_RAWKEY) {
  511.                 DisplayBeep(NULL);
  512.             } else if (msg->Class == IDCMP_MENUPICK) {
  513.                 menu_num = msg->Code;
  514.                 while (!done && (menu_num != MENUNULL)) {
  515.                     done |= DoMenu(MENUNUM(menu_num), ITEMNUM(menu_num));
  516.                     menu_num = ItemAddress(menu_strip, menu_num)->NextSelect;
  517.                 }
  518.                 ActivateGadget(text1_object, window, NULL);
  519.             }
  520.             ReplyMsg((struct Message *)msg);
  521.         }
  522.         if (!done) {
  523.             Wait(sigs);
  524.         }
  525.     }
  526. }
  527.  
  528. /*
  529.  * ActivateTabGadget()
  530.  *
  531.  * This function scans a window's gadget list and activates the
  532.  * first gadget that supports tab cycling.
  533.  *
  534.  * It should be called when your window gets a VANILLAKEY message
  535.  * with a TAB code (0x09).  This gives the user a way to start
  536.  * tab cycling through gadgets.
  537.  */
  538.  
  539. static void ActivateTabGadget(struct Window *window)
  540. {
  541.     struct Gadget *gad;
  542.  
  543.     for (gad = window->FirstGadget; gad != NULL; gad = gad->NextGadget) {
  544.         if ((gad->Flags & GFLG_TABCYCLE) && !(gad->Flags & GFLG_DISABLED)) {
  545.             ActivateGadget(gad, window, NULL);
  546.             break;
  547.         }
  548.     }
  549. }
  550.  
  551. /*
  552.  * DoMenu()
  553.  *
  554.  * Handle the Edit menu items
  555.  */
  556.  
  557. static BOOL DoMenu(UWORD menu, UWORD item)
  558. {
  559.     switch (menu) {
  560.         case PROJECT_MENU:
  561.             switch (item) {
  562.                 case ABOUT_ITEM:
  563.                     EasyRequest(window, &about_req, NULL, TEXTFIELD_GetCopyright());
  564.                     break;
  565.  
  566.                 case QUIT_ITEM:
  567.                     return TRUE;
  568.                     break;
  569.             }
  570.             break;
  571.  
  572.         case EDIT_MENU:
  573.             {
  574.                 ULONG tag = 0;
  575.  
  576.                 switch (item) {
  577.                     case CUT_ITEM:
  578.                         tag = TEXTFIELD_Cut;
  579.                         break;
  580.  
  581.                     case COPY_ITEM:
  582.                         tag = TEXTFIELD_Copy;
  583.                         break;
  584.  
  585.                     case COPYALL_ITEM:
  586.                         tag = TEXTFIELD_CopyAll;
  587.                         break;
  588.  
  589.                     case PASTE_ITEM:
  590.                         tag = TEXTFIELD_Paste;
  591.                         break;
  592.  
  593.                     case UNDO_ITEM:
  594.                         tag = TEXTFIELD_Undo;
  595.                         break;
  596.  
  597.                     case ERASE_ITEM:
  598.                         tag = TEXTFIELD_Erase;
  599.                         break;
  600.                 }
  601.                 if (tag > 0) {
  602.                     SetGadgetAttrs(text1_object, window, NULL, tag, 0, TAG_DONE);
  603.                 }
  604.             }
  605.             break;
  606.     }
  607.  
  608.     return FALSE;
  609. }
  610.  
  611. /*
  612.  * SetupPrefsWindow()
  613.  *
  614.  * Opens the preferences window generated by GadToolsBox
  615.  */
  616.  
  617. static BOOL SetupPrefsWindow(void)
  618. {
  619.     if (SetupScreen() == 0) {
  620.         if (OpenTextFieldPrefsWindow() == 0) {
  621.             return TRUE;
  622.         } else {
  623.             CloseDownScreen();
  624.         }
  625.     }
  626.  
  627.     return FALSE;
  628. }
  629.  
  630. /*
  631.  * ShutdownPrefsWindow()
  632.  *
  633.  * Closes the preferences window generated by GadToolsBox
  634.  */
  635.  
  636. static void ShutdownPrefsWindow(void)
  637. {
  638.     CloseTextFieldPrefsWindow();
  639.     CloseDownScreen();
  640. }
  641.